package com.pan.structual.facade.facade.impl;

import com.pan.structual.facade.component.FrameCreate;
import com.pan.structual.facade.component.ShapeCreate;
import com.pan.structual.facade.facade.DrawFacade;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;

public class DrawTextInShapeFacade implements DrawFacade {

    FrameCreate frameCreate = new FrameCreate();
    ShapeCreate shapeCreate = new ShapeCreate();

    @Override
    public void printShape(String shape, Color color, String text) {
        shapeCreate.setShape(shape);
        shapeCreate.setColor(color);
        Arrays.stream(DrawTextInShapeFacade.class.getClassLoader().getDefinedPackages()).map(pk->pk.getName()).forEach(System.out::println);

        BufferedImage shapeImage = shapeCreate.getShapeImage();
        Graphics2D graphics = shapeImage.createGraphics();
        graphics.setColor(Color.BLACK);
        graphics.setFont(new Font("TimesNewRoman",Font.PLAIN,14));
        graphics.drawString(text,0,10);
        graphics.dispose();

        shapeImage.flush();

        frameCreate.printShape(shapeImage);


    }
}
